home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Util / Extract / extract.c
Encoding:
C/C++ Source or Header  |  1994-12-22  |  1.9 KB  |  138 lines

  1.  
  2. #include <dos/dosasl.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #ifdef __SAS
  11. extern void __regargs __chkabort (void);
  12. /* disable ^C checking */
  13. void __regargs __chkabort (void) { /* empty */ }
  14. #endif
  15.  
  16.  
  17. __aligned struct AnchorPath ap;
  18. char search[64] = "";
  19. int searchlen;
  20. int ccomment;
  21. char line[256];
  22.  
  23. int stop;
  24.  
  25. void ProcessFile (void)
  26. {
  27.     int do_put;
  28.     FILE * fh;
  29.     char * ptr, * ptr2;
  30.  
  31.     if (!(fh = fopen (ap.ap_Info.fib_FileName, "r")) )
  32.     {
  33.     printf ("Cannot open %s for reading: %s\n",
  34.         ap.ap_Info.fib_FileName, strerror (errno));
  35.     return;
  36.     }
  37.  
  38.     do_put = 0;
  39.     stop = 0;
  40.  
  41.     while (fgets (line, sizeof (line), fh))
  42.     {
  43.     if (SetSignal (0,0) & SIGBREAKF_CTRL_C)
  44.     {
  45.         SetSignal (0, SIGBREAKF_CTRL_C);
  46.         puts ("*** Break");
  47.         stop = 1;
  48.         break;
  49.     }
  50.  
  51.     ptr = line;
  52.  
  53.     if (!strncmp (search, line, searchlen))
  54.     {
  55.         do_put = 1;
  56.         ptr += searchlen+1;
  57.     }
  58.  
  59.     if (do_put)
  60.     {
  61.         if (!ccomment)
  62.         {
  63.         fputs (line, stdout);
  64.         do_put = 0;
  65.         }
  66.         else
  67.         {
  68.         ptr2 = ptr;
  69.         while (*ptr2)
  70.         {
  71.             if (ptr2[0] == '*' && ptr2[1] == '/')
  72.             break;
  73.  
  74.             ptr2 ++;
  75.         }
  76.  
  77.         if (*ptr2)
  78.         {
  79.             do_put = 0;
  80.             *ptr2 = 0;
  81.         }
  82.  
  83.         fputs (ptr, stdout);
  84.  
  85.         if (!do_put)
  86.             putchar ('\n');
  87.         }
  88.     }
  89.     }
  90.  
  91.     fclose (fh);
  92. } /* ProcessFile */
  93.  
  94. #define NEXT    argv ++, argc --
  95.  
  96. int main (int argc, char ** argv)
  97. {
  98.     int error;
  99.  
  100.     ap.ap_BreakBits  = SIGBREAKF_CTRL_C;
  101.  
  102.     NEXT;
  103.  
  104.     if (!argc)
  105.     return 0;
  106.  
  107.     strcat (search, *argv);
  108.     searchlen = strlen (search);
  109.  
  110.     ccomment = (search[0] == '/' && search[1] == '*');
  111.  
  112.     NEXT;
  113.  
  114.     while (argc)
  115.     {
  116.     BPTR fl;
  117.  
  118.     for (error = MatchFirst (*argv, &ap); !error; error = MatchNext (&ap))
  119.     {
  120.         fl = CurrentDir (ap.ap_Current->an_Lock);
  121.         ProcessFile ();
  122.         CurrentDir (fl);
  123.  
  124.         if (stop)
  125.         break;
  126.     }
  127.  
  128.     MatchEnd (&ap);
  129.  
  130.     if (stop)
  131.         break;
  132.  
  133.     NEXT;
  134.     }
  135.  
  136.     return 0;
  137. } /* main */
  138.